package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;

public class AOPAdvice {

 /*   public void before() {
        System.out.println("before");
    }

    public void after() {
        System.out.println("after");
    }

    public void afterReturning() {
        System.out.println("afterReturning");
    }

    public void afterThrowing() {
        System.out.println("afterThrowing");
    }
*/

//    public void around(ProceedingJoinPoint pjp) {
//        try {
//            System.out.println("before");
//            Object ret = pjp.proceed();
//            System.out.println("after");
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//            System.out.println("afterThrowing");
//        }finally {
//            System.out.println("afterReturning");
//        }
//    }

    public Object around(ProceedingJoinPoint pjp) {
        Object[] args = pjp.getArgs();
        Object ret =null;
        try {
            System.out.println("before"+args[0]+","+args[1]);
            ret = pjp.proceed();
            System.out.println("after");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("afterThrowing");
        }finally {
            System.out.println("afterReturning");
        }

        return ret;
    }
}
